package com.zetyun.tiger.format.rate;

import com.zetyun.rt.meta.annotation.ActionMeta;
import com.zetyun.rt.sdk.action.MapAction;
import com.zetyun.rt.sdk.model.RtEvent;
import com.zetyun.rt.sdk.operator.OperatorContext;

@ActionMeta(
        id = "tiger.format-curr",
        tags = {"formatter"},
        category = "map",
        name = "ForamtCurrAction",
        parameterClass = FormatCurrParameter.class,
        description = "格式化货币信息"
)
public class ForamtCurrAction extends MapAction {


    private FormatCurrParameter param;

    @Override
    public void init(OperatorContext context) {
        super.init(context);
        param = context.getParameters();

    }

    @Override
    public RtEvent apply(RtEvent in) throws Exception {

        String code = in.getField(param.getInField(), String.class);

        if (code == null || code.isEmpty()) {
            // two space
            code = "01";
        }
        in.setValue(param.getCurrKeyField(),
                param.getOutField().concat(code).concat(param.getFxrTypField()));

        in.setValue(param.getDefaultRateField(), "1");
        return in;
    }
}
